
//********************init Config */
export function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return decodeURIComponent(r[2]); return null; //返回参数值
}

export function getCurrentHostPath(dir = '') {
    let Config = {};
    Config.localPath = '';
    if(window.location) {
        console.log(window.location);
        var subDir = '/' + dir;
        if(window.__gTextDev) {
            var cepPath = getUrlParam("cep")
            Config.cep = cepPath ? cepPath : "D:\\ECIDI\\CityMaker SDK\\CityMakerServerData\\test.cep";
        }
        if(window.location.port) {
            Config.localPath =  window.location.protocol + '\/\/'+ window.location.hostname + ':' + window.location.port + subDir;
        } else {
            Config.localPath = window.location.protocol + '\/\/'+ window.location.hostname + subDir;
        }
        console.log(Config.localPath);
    }
    return Config.localPath;
}
export function getWidth() {
    return parseInt(window.getComputedStyle(document.getElementById("renderControl"), null).width);
}
export function getHeight() {
    return parseInt(window.getComputedStyle(document.getElementById("renderControl"), null).height);
}

export function callParentMethod(data) {
    if(window.config && window.config.callParentMethodName){
        const callParent = window.parent.window[window.config.callParentMethodName];
        if(typeof callParent === "function"){
            return callParent(data);
        }
    }
    return false;
}